/*** m6809: Portable 6809 emulator ******************************************/

#pragma once

#ifndef __M6809_H__
#define __M6809_H__

enum
{
	M6809_PC=1, M6809_S, M6809_CC ,M6809_A, M6809_B, M6809_U, M6809_X, M6809_Y,
	M6809_DP
};

#define M6809_IRQ_LINE	0	/* IRQ line number */
#define M6809_FIRQ_LINE 1   /* FIRQ line number */

typedef struct _m6809_config m6809_config;
struct _m6809_config
{
	UINT8	encrypt_only_first_byte;		/* encrypt only the first byte in 10 xx and 11 xx opcodes */
};

typedef struct _m68_state_t m68_state_t;
struct _m68_state_t
{
	PAIR	pc; 		/* Program counter */
	PAIR	ppc;		/* Previous program counter */
	PAIR	d;		/* Accumulator a and b */
	PAIR	dp; 		/* Direct Page register (page in MSB) */
	PAIR	u, s;		/* Stack pointers */
	PAIR	x, y;		/* Index registers */
	UINT8	cc;
	UINT8	ireg;		/* First opcode */
	UINT8	irq_state[2];

	int 	extra_cycles; /* cycles used up by interrupts */
	//cpu_irq_callback irq_callback;
//	device_config *device;
    m6809_config *config;
	int		icount;
	PAIR	ea;			/* effective address */

	/* Memory spaces */
    address_space *program;

	UINT8	int_state;	/* SYNC and CWAI flags */
	UINT8	nmi_state;
};

// CPU Interface
class CM6809 : public CBaseCPU {
	private:
			m68_state_t* cpu;

	public:
			int Init(int clock);
			int Exec(int cycles);
			void Interrupt(int line, int state);
			void AssignMMU(int slot, CBaseMMU *mmu);
			void Reset();
			void Shutdown();

};

#endif /* __M6809_H__ */
